package com.youdoneed.community.forumConfig.web;

import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forumConfig.entity.Forumconfiguration;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.youdoneed.community.forumConfig.service.ForumconfigurationService;


/**
 * Created by xz on 2017/6/19.
 */
@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "/forumconfiguration" , method = {RequestMethod.GET,RequestMethod.POST})
@Api(value = "帖子配置模块控制器", description = "帖子配置模块相关操作")
public class ForumconfigurationController {

    private static final Logger logger = LoggerFactory.getLogger(ForumconfigurationController.class);

    @Autowired
    ForumconfigurationService forumconfigurationService;

    /**
     * 获取猿圈配置
     * @author xz
     * @return ResultMessage
     * @date 2017.6.19
     */
	@RequestMapping(value = "/getForumconfiguration", method = {RequestMethod.GET,RequestMethod.POST})
    @ApiOperation(notes = "后台获取猿圈配置", value = "后台获取猿圈配置")
    public ResultMessage<List<Forumconfiguration>> getForumconfiguration(){
        logger.info("后台获取猿圈配置");
        //获取猿圈配置信息
        Forumconfiguration configuration = forumconfigurationService.getConfiguration();
        List<Forumconfiguration> list=new ArrayList<Forumconfiguration>();
        if(null == configuration){
            logger.info("获取猿圈配置信息失败！");
        }
        list.add(configuration);
        return ResultMessage.newSuccess("获取首页帖子成功").setData(list);
    }

    /**
     * 修改猿圈配置
     * @author xz
     * @return ResultMessage
     * @date 2017.6.19
     */
    @RequestMapping(value = "/updataForumconfiguration", method = {RequestMethod.GET,RequestMethod.POST})
    @ApiOperation(notes = "后台修改猿圈配置", value = "后台修改猿圈配置")
    public ResultMessage<?> updataForumconfiguration(Forumconfiguration record){
        //修改猿圈配置信息
    	int forumconfiguration=forumconfigurationService.updataConfiguration(record);
        return ResultMessage.newSuccess("后台修改猿圈配置成功！").setData(forumconfiguration);
    }
}
